package leaveSystem.bizlogic;

import java.util.ArrayList;

import leaveSystem.dao.DAOException;
import leaveSystem.dao.ViewLeaveDAO;
import leaveSystem.dao.ViewLeaveDAOFactory;
import leaveSystem.model.EmpLeave;

public class ViewLeaveManager {
	private ViewLeaveDAO viewLeaveDAO;

	public ViewLeaveManager() {
		viewLeaveDAO = ViewLeaveDAOFactory.loadInstance().getViewLeaveDAO();
	}

	@SuppressWarnings("finally")
	public ArrayList<EmpLeave> getApplicationForApproval(int mgrid) {
		ArrayList<EmpLeave> empleaves = new ArrayList<EmpLeave>();
		try {
			empleaves = viewLeaveDAO.getApplicationForApproval(mgrid);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return empleaves;
		}
	}
	
	public EmpLeave getEmpLeave(int leaveid){
		EmpLeave empleave=new EmpLeave();
		try {
			empleave=viewLeaveDAO.getEmpLeave(leaveid);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return empleave;
	}
	
	public ArrayList<EmpLeave> getLeaveOnSamePeriod(EmpLeave empleave,int mgrid){
		ArrayList<EmpLeave> leavesonsameperiod=new ArrayList<EmpLeave>();
		try {
			leavesonsameperiod=viewLeaveDAO.getLeaveOnSamePeriod(empleave, mgrid);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return leavesonsameperiod;
	}
	
	public void submitDecision(String modifiedby,int leaveid,String approve,String comment){
		try {
			viewLeaveDAO.submitDecision(modifiedby,leaveid, approve, comment);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public ArrayList<EmpLeave> getEmployeeLeaveHistory(int mgrid){
		ArrayList<EmpLeave> empleaves=new ArrayList<EmpLeave>();
		try {
			empleaves = viewLeaveDAO.getEmployeeLeaveHistory(mgrid);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return empleaves;
	}
	
	public ArrayList<EmpLeave> getPersonalLeaveHistory(String operator,int empid){
		ArrayList<EmpLeave> empleaves=new ArrayList<EmpLeave>();
		try {
			empleaves=viewLeaveDAO.getPersonalLeaveHistory(operator, empid);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return empleaves;
	}
}
